﻿#region Copyright ©2008-2011, Technische Universitaet Muenchen
// ====================================================================================================
//
// Last Changed by       $Author: then $
// Last Changed Date     $LastChangedDate: 2009-05-15 14:42:13 +0200 (Fri, 15 May 2009) $
// Last Changed Revision $Rev: 139 $
//
// ====================================================================================================
#endregion

using System.Xml;
using Tum.CollabXT.VModellXT.Resources;
using System;

namespace Tum.CollabXT.VModellXT
{
    public class Product : ProcessElement, IArtifact
    {
        public Product() { }
        public Product(XmlNode node) 
        {
            Id = node.Attributes["id"].Value;
            Name = node.SelectSingleNode("Name").InnerText;
            TypeName = Name;

            XmlNode descNode = node.SelectSingleNode("Sinn_und_Zweck");
            ExtendedData["DescriptionRaw"] = descNode != null ? Helper.GetTextFromHtmlString(descNode.InnerXml) : string.Empty;

            #region Get text block if availabe
            XmlNode descTextIdNode = node.SelectSingleNode("TextbausteinRef/@link");
            if (descTextIdNode != null)
            {
                descNode = node.OwnerDocument.SelectSingleNode(string.Format(Queries.MDL_GetTextBlock, descTextIdNode.Value));
                if(descNode != null)
                    ExtendedData["DescriptionRaw"] = descNode.InnerText;
            }
            #endregion

            object desc;
            if(ExtendedData.TryGetValue("DescriptionRaw", out desc))
                Description = Helper.GetTextFromHtmlString(desc as string);

            IsInitial = node.Attributes["Initial"].Value.Equals("ja", StringComparison.OrdinalIgnoreCase);
            IsExternal = node.Attributes["Extern"].Value.Equals("ja", StringComparison.OrdinalIgnoreCase);

            XmlNode productTemplateNode = node.Attributes["Produktvorlage"];
            if (productTemplateNode != null)
                HasDocumentTemplate = node.Attributes["Produktvorlage"].Value.Equals("ja", StringComparison.OrdinalIgnoreCase);
        }


        #region IProduct Members

        public bool IsInitial
        {
            get; set;
        }

        public bool IsExternal
        {
            get; set;
        }

        public bool HasDocumentTemplate
        {
            get; set;
        }

        public string DocumentTemplatePath
        {
            get; set;
        }

        public string TypeName
        {
            get; set;
        }

        #endregion
    }
}
